
$(function () {

    loadCompanySelect();
    customerPoolIdSelectInit();

});

/**
 * 加载公司下拉列表
 */
function loadCompanySelect() {
    $.getJSON("/company/getCompanyList", function (data) {
        if (data.code == '000000') {
            var companyOptionHtml = '<option value="">请选择所属公司</option>';
            data.data.map(function (item) {
                companyOptionHtml += '<option value="' + item.companyId + '">' + item.companyName + '</option>';
            });
            $("#searchCompanySelect").html("");
            $('#searchCompanySelect').append(companyOptionHtml);
            $('#searchCompanySelect').selectpicker('refresh');

            $("#searchCompanySelect2").html("");
            $('#searchCompanySelect2').append(companyOptionHtml);
            $('#searchCompanySelect2').selectpicker('refresh');

            $("#searchCompanySelect3").html("");
            $('#searchCompanySelect3').append(companyOptionHtml);
            $('#searchCompanySelect3').selectpicker('refresh');

            $("#searchCompanySelect4").html("");
            $('#searchCompanySelect4').append(companyOptionHtml);
            $('#searchCompanySelect4').selectpicker('refresh');

            $("#searchCompanySelect5").html("");
            $('#searchCompanySelect5').append(companyOptionHtml);
            $('#searchCompanySelect5').selectpicker('refresh');

            $("#searchCompanySelect6").html("");
            $('#searchCompanySelect6').append(companyOptionHtml);
            $('#searchCompanySelect6').selectpicker('refresh');

            $("#searchCompanySelect7").html("");
            $('#searchCompanySelect7').append(companyOptionHtml);
            $('#searchCompanySelect7').selectpicker('refresh');
            $("#returnMoneyCompanySelect").empty();
            $('#returnMoneyCompanySelect').append(companyOptionHtml);
            $('#returnMoneyCompanySelect').selectpicker('refresh');
        }
    });
}

/**
 * 告知用户密码
 */
function sendPasswordTo() {
    var companyId = $("#searchCompanySelect").val();
    if ("" == companyId || !companyId){
        $.alert({
            title: '温馨提示',
            content: '请选择公司！',
        });
        return;
    }
    var url = '/account/sendUserPasswordToMail?companyId='+companyId;
    $.ajax({
        url: url,
        type: 'get',
        dataType:"json",
        contentType:false,
        processData: false,
        success:(function(data) {
            if(data.code == "000000"){

                $.alert({
                    title: '提示',
                    content: "操作成功",
                    buttons: {
                        confirm: {
                            text: '确认',
                            btnClass: 'btn-primary',
                            action: function () {
                                $("#importCallFile").val("");
                                window.location.reload();
                            }
                        }
                    }
                });
                $('#importCallModal').modal('hide');
            }else{
                $.alert("发送失败");
            }
        }),
        error:(function() {
            $.alert("发送失败！");
        })
    });
}

/**
 * 告知用户密码
 */
function sendPasswordTo2() {
    var companyId = $("#searchCompanySelect5").val();
    var sendMail = $("#sendMail").val();
    if ("" == companyId || !companyId){
        $.alert({
            title: '温馨提示',
            content: '请选择公司！',
        });
        return;
    }
    if (!sendMail){
        $.alert({
            title: '温馨提示',
            content: '请输入要接收密码的邮箱！',
        });
        return;
    }
    var url = '/account/sendLeaveUserPasswordToMail?companyId='+companyId+"&sendMail="+sendMail;
    $.ajax({
        url: url,
        type: 'get',
        dataType:"json",
        contentType:false,
        processData: false,
        success:(function(data) {
            if(data.code == "000000"){

                $.alert({
                    title: '提示',
                    content: "操作成功",
                    buttons: {
                        confirm: {
                            text: '确认',
                            btnClass: 'btn-primary',
                            action: function () {
                                $("#importCallFile").val("");
                                window.location.reload();
                            }
                        }
                    }
                });
                $('#importCallModal').modal('hide');
            }else{
                $.alert("发送失败");
            }
        }),
        error:(function() {
            $.alert("发送失败！");
        })
    });
}

//导入账号信息
function importUserList(type) {
    if(type == 1 && !document.getElementById('importCallFile').files[0]){
        $.alert({
            title: '温馨提示',
            content: '请选择文件！',
        });
        return;
    }
    if(type == 2 && !document.getElementById('importCallFile5').files[0]){
        $.alert({
            title: '温馨提示',
            content: '请选择文件！',
        });
        return;
    }
    var fileName = "";
    var fileType = "";
    if (type == 1){
        fileName = document.getElementById('importCallFile').files[0].name;
        fileType = fileName.substring(fileName.lastIndexOf("."), fileName.length);
    }

    if (type == 2){
        fileName = document.getElementById('importCallFile5').files[0].name;
        fileType = fileName.substring(fileName.lastIndexOf("."), fileName.length);
    }
    var  companyId = $("#searchCompanySelect").val();
    if (type == 2){
        companyId = $("#searchCompanySelect5").val();
    }
    if (!companyId){
        $.alert({
            title: '温馨提示',
            content: '请选择导入账号的所属公司！',
        });
        return;
    }

    var formData = new FormData();
    var file = "";
    if (type == 1){
        file = $("#importCallFile")[0].files[0];
    }
    if (type == 2){
        file = $("#importCallFile5")[0].files[0];
    }
    //接口接收参数 键值形式 添加到formData中
    formData.append("file",file);
    formData.append("type",type);
    if (type == 1){
        formData.append("companyId",$("#searchCompanySelect").val());
    }
    if (type == 2){
        formData.append("companyId",companyId);
    }
    if(fileName!="" && fileType.toLocaleUpperCase()==".XLSX"){
        $.ajax({
            url: '/account/importUserAccount',
            type: 'POST',
            dataType:"json",
            contentType:false,
            data: formData,
            processData: false,
            success:(function(data) {
                if(data.code == "000000"){
                    //线索导入数量
                    var importCallNum = data.data.importCallNum;
                    var repeatIdStr = data.data.repeatIdStr;
                    var importFailIdStr = data.data.importFailIdStr;

                    //返回内容
                    var content = "";

                    //导入数量大于0
                    if(importCallNum>0){
                        content = "成功导入"+importCallNum+"条数据";
                    }
                    //重复id不为空
                    if(repeatIdStr!=""){
                        content = content + "<br>excel表格第：" + repeatIdStr + "行号码已存在";
                    }
                    //失败id不为空
                    if(importFailIdStr!=""){
                        content = content + "<br>excel表格第：" + importFailIdStr + "行信息导入失败";
                    }

                    $.alert({
                        title: '提示',
                        content: content,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'btn-primary',
                                action: function () {
                                    $("#importCallFile").val("");
                                    window.location.reload();
                                }
                            }
                        }
                    });
                    $('#importCallModal').modal('hide');
                    $("#importCallFile").val("");
                }else{
                    $.alert("导入失败");
                    $("#importCallFile").val("");
                }
            }),
            error:(function() {
                $.alert("导入出错！");
                $("#importCallFile").val("");
            })
        });
    } else {
        $.alert({
            title: '温馨提示',
            content: '请上传.xlsx文件！',
        });
    }
}

//导入跟进记录
function importFollowList() {
    if(!document.getElementById('importFollowFile').files[0]){
        $.alert({
            title: '温馨提示',
            content: '请选择文件！',
        });
        return;
    }
    var fileName = document.getElementById('importFollowFile').files[0].name;
    var fileType = fileName.substring(fileName.lastIndexOf("."), fileName.length);
    var formData = new FormData();
    //接口接收参数 键值形式 添加到formData中
    formData.append("file",$("#importFollowFile")[0].files[0]);
    formData.append("companyId",$("#searchCompanySelect2").val());
    if(fileName!="" && fileType.toLocaleUpperCase()==".XLSX"){
        $.ajax({
            url: '/clueFollow/importFollow',
            type: 'POST',
            dataType:"json",
            contentType:false,
            data: formData,
            processData: false,
            success:(function(data) {
                if(data.code == "000000"){
                    //线索导入数量
                    var importCallNum = data.data.importClueNum;
                    var repeatIdStr = data.data.repeatIdStr;
                    var importFailIdStr = data.data.importFailIdStr;

                    //返回内容
                    var content = "";

                    //导入数量大于0
                    if(importCallNum>0){
                        content = "成功导入"+importCallNum+"条数据";
                    }
                    //重复id不为空
                    if(repeatIdStr!=""){
                        content = content + "<br>excel表格第：" + repeatIdStr + "行号码已存在";
                    }
                    //失败id不为空
                    if(importFailIdStr!=""){
                        content = content + "<br>excel表格第：" + importFailIdStr + "行信息导入失败";
                    }

                    $.alert({
                        title: '提示',
                        content: content,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'btn-primary',
                                action: function () {
                                    $("#importCallFile").val("");
                                    window.location.reload();
                                }
                            }
                        }
                    });
                    $('#importCallModal').modal('hide');
                    $("#importCallFile").val("");
                }else{
                    $.alert("导入失败");
                    $("#importCallFile").val("");
                }
            }),
            error:(function() {
                $.alert("导入出错！");
                $("#importCallFile").val("");
            })
        });
    } else {
        $.alert({
            title: '温馨提示',
            content: '请上传.xlsx文件！',
        });
    }
}

//导入到款记录
function importReturnMoneyList() {
    if(!document.getElementById('importReturnMoneyFile').files[0]){
        $.alert({
            title: '温馨提示',
            content: '请选择文件！',
        });
        return;
    }
    var fileName = document.getElementById('importReturnMoneyFile').files[0].name;
    var fileType = fileName.substring(fileName.lastIndexOf("."), fileName.length);
    var formData = new FormData();
    //接口接收参数 键值形式 添加到formData中
    formData.append("file",$("#importReturnMoneyFile")[0].files[0]);
    formData.append("companyId",$("#searchCompanySelect4").val());
    if(fileName!="" && fileType.toLocaleUpperCase()==".XLSX"){
        $.ajax({
            url: '/returnMoney/importReturnMoney',
            type: 'POST',
            dataType:"json",
            contentType:false,
            data: formData,
            processData: false,
            success:(function(data) {
                if(data.code == "000000"){
                    //线索导入数量
                    var importCallNum = data.data.importClueNum;
                    var repeatIdStr = data.data.repeatIdStr;
                    var importFailIdStr = data.data.importFailIdStr;

                    //返回内容
                    var content = "";

                    //导入数量大于0
                    if(importCallNum>0){
                        content = "成功导入"+importCallNum+"条数据";
                    }
                    //重复id不为空
                    if(repeatIdStr!=""){
                        content = content + "<br>excel表格第：" + repeatIdStr + "行号码已存在";
                    }
                    //失败id不为空
                    if(importFailIdStr!=""){
                        content = content + "<br>excel表格第：" + importFailIdStr + "行信息导入失败";
                    }

                    $.alert({
                        title: '提示',
                        content: content,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'btn-primary',
                                action: function () {
                                    $("#importCallFile").val("");
                                    window.location.reload();
                                }
                            }
                        }
                    });
                    $('#importCallModal').modal('hide');
                    $("#importCallFile").val("");
                }else{
                    $.alert("导入失败");
                    $("#importCallFile").val("");
                }
            }),
            error:(function() {
                $.alert("导入出错！");
                $("#importCallFile").val("");
            })
        });
    } else {
        $.alert({
            title: '温馨提示',
            content: '请上传.xlsx文件！',
        });
    }
}

//导入退款记录
function importBackMoneyList() {
    if(!document.getElementById('importBackMoneyFile').files[0]){
        $.alert({
            title: '温馨提示',
            content: '请选择文件！',
        });
        return;
    }
    var fileName = document.getElementById('importBackMoneyFile').files[0].name;
    var fileType = fileName.substring(fileName.lastIndexOf("."), fileName.length);
    var formData = new FormData();
    //接口接收参数 键值形式 添加到formData中
    formData.append("file",$("#importBackMoneyFile")[0].files[0]);
    formData.append("companyId",$("#searchCompanySelect7").val());
    if(fileName!="" && fileType.toLocaleUpperCase()==".XLSX"){
        $.ajax({
            url: '/returnMoney/importBackMoney',
            type: 'POST',
            dataType:"json",
            contentType:false,
            data: formData,
            processData: false,
            success:(function(data) {
                if(data.code == "000000"){
                    //线索导入数量
                    var importCallNum = data.data.importCallNum;
                    var repeatIdStr = data.data.repeatIdStr;
                    var importFailIdStr = data.data.importFailIdStr;

                    //返回内容
                    var content = "";

                    //导入数量大于0
                    if(importCallNum>0){
                        content = "成功导入"+importCallNum+"条数据";
                    }
                    //重复id不为空
                    if(repeatIdStr!=""){
                        content = content + "<br>excel表格第：" + repeatIdStr + "行号码已存在";
                    }
                    //失败id不为空
                    if(importFailIdStr!=""){
                        content = content + "<br>excel表格第：" + importFailIdStr + "行信息导入失败";
                    }

                    $.alert({
                        title: '提示',
                        content: content,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'btn-primary',
                                action: function () {
                                    $("#importCallFile").val("");
                                    window.location.reload();
                                }
                            }
                        }
                    });
                    $('#importCallModal').modal('hide');
                    $("#importCallFile").val("");
                }else{
                    $.alert("导入失败");
                    $("#importCallFile").val("");
                }
            }),
            error:(function() {
                $.alert("导入出错！");
                $("#importCallFile").val("");
            })
        });
    } else {
        $.alert({
            title: '温馨提示',
            content: '请上传.xlsx文件！',
        });
    }
}

/**
 * 初始化客户池名称下拉
 */
function customerPoolIdSelectInit(){
    $.ajax({
        type: 'get',
        url: '/customer/selectEnableCustomerPoolName',
        success: function (data) {
            let customerPoolList = data.data;
            let customerPoolOptionStr = "";
            for (let index in customerPoolList) {
                let jsonObj = customerPoolList[index];
                customerPoolOptionStr += "<option value=\"" + jsonObj.customerPoolId + "\">" + jsonObj.customerPoolName + "</option>";
                $("#customerPoolIdSelect").html("<option value=''>请选择客户池名称</option>" + customerPoolOptionStr);
            }
            // 刷新下拉框
            $("#customerPoolIdSelect").selectpicker('refresh');
        }
    });
}

//导入客户
function importCustomerList() {
    if(!document.getElementById('importCustomerFile').files[0]){
        $.alert({
            title: '温馨提示',
            content: '请选择文件！',
        });
        return;
    }
    var customerPoolId = $('#customerPoolIdSelect').val();//客户池主键
    //客户池名称为空判断
    if(!customerPoolId){
        $.alert("客户池名称不能为空！");
        return;
    }
    var fileName = document.getElementById('importCustomerFile').files[0].name;
    var fileType = fileName.substring(fileName.lastIndexOf("."), fileName.length);
    var formData = new FormData();
    //接口接收参数 键值形式 添加到formData中
    formData.append("file",$("#importCustomerFile")[0].files[0]);
    formData.append("customerPoolId",customerPoolId);
    if(fileName!="" && (fileType.toLocaleUpperCase()==".XLSX" || fileType.toLocaleUpperCase()==".XLS")){
        $.ajax({
            url: '/customerImport/userCustomerImport',
            type: 'POST',
            dataType:"json",
            contentType:false,
            data: formData,
            processData: false,
            success:(function(data) {
                if(data.code == "000000"){
                    //客户导入数量
                    var importCustomerNum = data.data.importCustomerNum;
                    var repeatIdStr = data.data.repeatIdStr;
                    var importFailIdStr = data.data.importFailIdStr;
                    var customerNameOrCreditCodeNull = data.data.customerNameOrCreditCodeNull;
                    var ownerNull = data.data.ownerNull;
                    var customerTypeAndCreditCodeNull = data.data.customerTypeAndCreditCodeNull;
                    var wrongCustomerName = data.data.wrongCustomerName;
                    var wrongUnifiedSocialCreditCode = data.data.wrongUnifiedSocialCreditCode;
                    var contactInformationEmpty = data.data.contactInformationEmpty;

                    //返回内容
                    var content = "";

                    //导入数量大于0
                    if(importCustomerNum>0){
                        content = "成功导入"+importCustomerNum+"条数据";
                    } else {
                        content = "成功导入0条数据";
                    }

                    //重复id不为空
                    if(repeatIdStr!=""){
                        content = content + "<br>客户为第：" + repeatIdStr + "行数据，客户已存在";
                    }
                    //失败id不为空
                    if(importFailIdStr!=""){
                        content = content + "<br>客户为第：" + importFailIdStr + "行数据，导入失败";
                    }
                    //客户名称或统一社会信用代码为空id不为空
                    if(customerNameOrCreditCodeNull!=""){
                        content = content + "<br>客户为第：" + customerNameOrCreditCodeNull + "行数据，客户名称为空";
                    }
                    //账号表中未找到所有人id不为空
                    if(ownerNull!=""){
                        content = content + "<br>客户为第：" + ownerNull + "行数据，账号表中未找到所有人";
                    }
                    //客户类型和统一社会信用代码为空
                    if(customerTypeAndCreditCodeNull!=""){
                        content = content + "<br>客户为第：" + customerTypeAndCreditCodeNull + "行数据，客户类型和统一社会信用代码为空";
                    }
                    //客户名称错误
                    if(wrongCustomerName!=""){
                        content = content + "<br>客户为第：" + wrongCustomerName + "行数据，客户名称错误";
                    }
                    //统一社会信用代码错误
                    if(wrongUnifiedSocialCreditCode!=""){
                        content = content + "<br>客户为第：" + wrongUnifiedSocialCreditCode + "行数据，统一社会信用代码错误";
                    }
                    //个人客户联系方式为空
                    if(contactInformationEmpty!=""){
                        content = content + "<br>客户为第：" + contactInformationEmpty + "行数据，个人客户联系方式为空";
                    }

                    $.alert({
                        title: '提示',
                        content: content,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'btn-primary',
                                action: function () {
                                    $("#importCustomerFile").val("");
                                }
                            }
                        }
                    });
                    $('#importCustomerModal').modal('hide');
                    $("#importCustomerFile").val("");
                }else if(data.code == "IC0001"){
                    $.alert({
                        title: '提示',
                        content: data.message,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'btn-primary',
                                action: function () {
                                    $("#importCustomerFile").val("");
                                }
                            }
                        }
                    });
                }else{
                    $.alert("导入失败");
                    $("#importCustomerFile").val("");
                }
            }),
            error:(function() {
                $.alert("导入出错！");
                $("#importCustomerFile").val("");
            })
        });
    } else {
        $.alert({
            title: '温馨提示',
            content: '请上传.xlsx文件！',
        });
    }
}

//导入订单
function importOrderList() {
    if(!document.getElementById('importOrderFile').files[0]){
        $.alert({
            title: '温馨提示',
            content: '请选择文件！',
        });
        return;
    }
    var fileName = document.getElementById('importOrderFile').files[0].name;
    var fileType = fileName.substring(fileName.lastIndexOf("."), fileName.length);
    var formData = new FormData();
    //接口接收参数 键值形式 添加到formData中
    formData.append("file",$("#importOrderFile")[0].files[0]);
    if(fileName!="" && (fileType.toLocaleUpperCase()==".XLSX" || fileType.toLocaleUpperCase()==".XLS")){
        $.ajax({
            url: '/customerProductOrderImport/import',
            type: 'POST',
            dataType:"json",
            contentType:false,
            data: formData,
            processData: false,
            success:(function(data) {
                if(data.code == "000000"){
                    //订单导入数量
                    var importNum = data.data.importNum;
                    var repeatIdStr = data.data.repeatIdStr;
                    var importFailIdStr = data.data.importFailIdStr;
                    var contractNotExist = data.data.contractNotExist;
                    var customerNotExist = data.data.customerNotExist;
                    var otherOrders = data.data.otherOrders;
                    var ownerNull = data.data.ownerNull;

                    //返回内容
                    var content = "";

                    //导入数量大于0
                    if(importNum > 0){
                        content = "成功导入"+importNum+"条数据";
                    }
                    //重复id不为空
                    if(repeatIdStr != ""){
                        content = content + "<br>订单为第：" + repeatIdStr + "行数据，数据库已存在";
                    }
                    //失败id不为空
                    if(importFailIdStr != ""){
                        content = content + "<br>订单为第：" + importFailIdStr + "行数据导入失败";
                    }

                    //合同不存在不为空
                    if(contractNotExist != ""){
                        content = content + "<br>订单为第：" + contractNotExist + "行数据导入失败，合同不存在";
                    }

                    //客户不存在不为空
                    if(customerNotExist != ""){
                        content = content + "<br>订单为第：" + customerNotExist + "行数据导入失败，客户不存在";
                    }

                    //非生效中的其它订单不为空
                    if(otherOrders != ""){
                        content = content + "<br>订单为第：" + otherOrders + "行数据导入失败，只导入回款状态为已回款并且订单状态为生效中或者已结束的订单";
                    }

                    //所有人不存在不为空
                    if(ownerNull != ""){
                        content = content + "<br>订单为第：" + ownerNull + "行数据导入失败，所有人不存在";
                    }

                    $.alert({
                        title: '提示',
                        content: content,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'btn-primary',
                                action: function () {
                                    $("#importOrderFile").val("");
                                }
                            }
                        }
                    });
                    $("#importOrderFile").val("");
                } else {
                    $.alert("导入失败");
                    $("#importOrderFile").val("");
                }
            }),
            error:(function() {
                $.alert("导入出错！");
                $("#importOrderFile").val("");
            })
        });
    } else {
        $.alert({
            title: '温馨提示',
            content: '请上传.xlsx文件！',
        });
    }
}

//导入合同
function importContractList() {
    if(!document.getElementById('importContractFile').files[0]){
        $.alert({
            title: '温馨提示',
            content: '请选择文件！',
        });
        return;
    }
    var fileName = document.getElementById('importContractFile').files[0].name;
    var fileType = fileName.substring(fileName.lastIndexOf("."), fileName.length);
    var formData = new FormData();
    //接口接收参数 键值形式 添加到formData中
    formData.append("file",$("#importContractFile")[0].files[0]);
    if(fileName!="" && (fileType.toLocaleUpperCase()==".XLSX" || fileType.toLocaleUpperCase()==".XLS")){
        $.ajax({
            url: '/contract/contractImport',
            type: 'POST',
            dataType:"json",
            contentType:false,
            data: formData,
            processData: false,
            success:(function(data) {
                if(data.code == "000000"){
                    var importContractNum = data.data.importContractNum;
                    var customerEmptyIdList = data.data.customerEmptyIdList;
                    var customerNotExistIdList = data.data.customerNotExistIdList;
                    var repeatIdList = data.data.repeatIdList;
                    var ownerEmptyIdList = data.data.ownerEmptyIdList;
                    var importFailIdList = data.data.importFailIdList;
                    var notValidIdList = data.data.notValidIdList;

                    //返回内容
                    var content = "";

                    //导入数量大于0
                    content = "成功导入"+importContractNum+"条数据";
/*                    //客户为空
                    if(customerEmptyIdList!=""){
                        content = content + "<br>第：" + customerEmptyIdList + "行数据库客户为空，导入失败";
                    }
                    //客户不存在
                    if(customerNotExistIdList!=""){
                        content = content + "<br>第：" + customerNotExistIdList + "行数据客户不存在，导入失败";
                    }
                    //合同已存在
                    if(repeatIdList!=""){
                        content = content + "<br>第：" + repeatIdList + "行数据合同编号已存在，导入失败";
                    }
                    //未生效合同不能导入
                    if(notValidIdList!=""){
                        content = content + "<br>第：" + notValidIdList + "行数据合同状态没有生效中，导入失败";
                    }
                    //所有人不存在不能导入
                    if(ownerEmptyIdList!=""){
                        content = content + "<br>第：" + ownerEmptyIdList + "行数据所有人不存在，导入失败";
                    }
                    //导入失败
                    if(importFailIdList!=""){
                        content = content + "<br>第：" + importFailIdList + "行数据合同导入失败";
                    }*/


                    $.alert({
                        title: '提示',
                        content: content,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'btn-primary',
                                action: function () {
                                    $("#importContractFile").val("");
                                }
                            }
                        }
                    });
                    $("#importContractFile").val("");
                }else if(data.code == "CI0001"){
                    $.alert({
                        title: '提示',
                        content: data.message,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'btn-primary',
                                action: function () {
                                    $("#importContractFile").val("");
                                }
                            }
                        }
                    });
                }else{
                    $.alert("导入失败");
                    $("#importContractFile").val("");
                }
            }),
            error:(function() {
                $.alert("导入出错！");
                $("#importContractFile").val("");
            })
        });
    } else {
        $.alert({
            title: '温馨提示',
            content: '请上传.xlsx文件！',
        });
    }
}

//客户导入失败日志
function openCustomerLogPage() {
    openTab("客户日志","/front/customerManager/customerImportFailureLog");
    //重新加载相关table列表页面
    refreshActivePane('/front/customerManager/customerImportFailureLog');
}

//订单导入失败日志
function openOrderLogPage() {
    openTab("订单日志","/front/orderManager/orderImportFailureLog");
    //重新加载相关table列表页面
    refreshActivePane('/front/orderManager/orderImportFailureLog');
}

//导入失败日志
function openAllLogPage() {
    openTab("所有日志","/front/systemManager/importFailureLog");
    //重新加载相关table列表页面
    refreshActivePane('/front/systemManager/importFailureLog');
}



//导入联系人信息
function importContactList() {
    if(!document.getElementById('importContactFile').files[0]){
        $.alert({
            title: '温馨提示',
            content: '请选择文件！',
        });
        return;
    }
    var fileName = document.getElementById('importContactFile').files[0].name;
    var fileType = fileName.substring(fileName.lastIndexOf("."), fileName.length);
    var formData = new FormData();
    //接口接收参数 键值形式 添加到formData中
    formData.append("file",$("#importContactFile")[0].files[0]);
    formData.append("companyId",$("#searchCompanySelect3").val());
    if(fileName!="" && fileType.toLocaleUpperCase()==".XLSX"){
        $.ajax({
            url: '/contact/importContact',
            type: 'POST',
            dataType:"json",
            contentType:false,
            data: formData,
            processData: false,
            success:(function(data) {
                if(data.code == "000000"){
                    //线索导入数量
                    var importCallNum = data.data.importCallNum;
                    var repeatIdStr = data.data.repeatIdStr;
                    var importFailIdStr = data.data.importFailIdStr;

                    //返回内容
                    var content = "";

                    //导入数量大于0
                    content = "成功导入"+importCallNum+"条数据";

                    //重复id不为空
                    if(repeatIdStr!=""){
                        content = content + "<br>excel表格第：" + repeatIdStr + "行号码已存在";
                    }
                    //失败id不为空
                    if(importFailIdStr!=""){
                        content = content + "<br>excel表格第：" + importFailIdStr + "行信息导入失败";
                    }

                    $.alert({
                        title: '提示',
                        content: content,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'btn-primary',
                                action: function () {
                                    $("#importCallFile").val("");
                                    window.location.reload();
                                }
                            }
                        }
                    });
                    //$('#importCallModal').modal('hide');
                    $("#importContactFile").val("");
                }else{
                    $.alert("导入失败");
                    $("#importContactFile").val("");
                }
            }),
            error:(function() {
                $.alert("导入出错！");
                $("#importContactFile").val("");
            })
        });
    } else {
        $.alert({
            title: '温馨提示',
            content: '请上传.xlsx文件！',
        });
    }
}

//导入会员卡信息
function importMembershipCardList() {
    if(!document.getElementById('importCallFile6').files[0]){
        $.alert({
            title: '温馨提示',
            content: '请选择文件！',
        });
        return;
    }
    var fileName = document.getElementById('importCallFile6').files[0].name;
    var fileType = fileName.substring(fileName.lastIndexOf("."), fileName.length);
    var formData = new FormData();
    //接口接收参数 键值形式 添加到formData中
    formData.append("file",$("#importCallFile6")[0].files[0]);
    formData.append("companyId",$("#searchCompanySelect6").val());
    if(fileName!="" && fileType.toLocaleUpperCase()==".XLSX"){
        $.ajax({
            url: '/memberShipCard/importMembershipCard',
            type: 'POST',
            dataType:"json",
            contentType:false,
            data: formData,
            processData: false,
            success:(function(data) {
                if(data.code == "000000"){
                    //线索导入数量
                    var importCallNum = data.data.importCallNum;
                    var repeatIdStr = data.data.repeatIdStr;
                    var importFailIdStr = data.data.importFailIdStr;

                    //返回内容
                    var content = "";

                    //导入数量大于0
                    if(importCallNum>0){
                        content = "成功导入"+importCallNum+"条数据";
                    }
                    //重复id不为空
                    if(repeatIdStr!=""){
                        content = content + "<br>excel表格第：" + repeatIdStr + "行号码已存在";
                    }
                    //失败id不为空
                    if(importFailIdStr!=""){
                        content = content + "<br>excel表格第：" + importFailIdStr + "行信息导入失败";
                    }

                    $.alert({
                        title: '提示',
                        content: content,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'btn-primary',
                                action: function () {
                                    $("#importCallFile").val("");
                                    window.location.reload();
                                }
                            }
                        }
                    });
                    //$('#importCallModal').modal('hide');
                    $("#importContactFile").val("");
                }else{
                    $.alert("导入失败");
                    $("#importContactFile").val("");
                }
            }),
            error:(function() {
                $.alert("导入出错！");
                $("#importContactFile").val("");
            })
        });
    } else {
        $.alert({
            title: '温馨提示',
            content: '请上传.xlsx文件！',
        });
    }
}

//导入会员卡信息
function importCard() {
    if(!document.getElementById('importCallFile7').files[0]){
        $.alert({
            title: '温馨提示',
            content: '请选择文件！',
        });
        return;
    }
    var fileName = document.getElementById('importCallFile7').files[0].name;
    var fileType = fileName.substring(fileName.lastIndexOf("."), fileName.length);
    var formData = new FormData();
    //接口接收参数 键值形式 添加到formData中
    formData.append("file",$("#importCallFile7")[0].files[0]);
    //formData.append("companyId",$("#searchCompanySelect6").val());
    if(fileName!="" && fileType.toLocaleUpperCase()==".XLSX"){
        $.ajax({
            url: '/contact/importCard',
            type: 'POST',
            dataType:"json",
            contentType:false,
            data: formData,
            processData: false,
            success:(function(data) {
                if(data.code == "000000"){

                    $.alert({
                        title: '提示',
                        content: content,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'btn-primary',
                                action: function () {
                                    $("#importCallFile").val("");
                                    window.location.reload();
                                }
                            }
                        }
                    });

                    $("#importCallFile7").val("");
                }else{
                    $.alert("导入失败");
                    $("#importCallFile7").val("");
                }
            }),
            error:(function() {
                $.alert("导入出错！");
                $("#importCallFile7").val("");
            })
        });
    } else {
        $.alert({
            title: '温馨提示',
            content: '请上传.xlsx文件！',
        });
    }
}

function comparisonData() {
    $.ajax({
        url: '/contact/comparisonData',
        type: 'POST',
        dataType:"json",
        contentType:false,
        data:"",
        success:(function(data) {
            if(data.code == "000000"){
                //插入数量
                var importCallNum = data.data;
                //导入数量大于0
                var content = "成功插入"+importCallNum+"条数据";

                $.alert({
                    title: '提示',
                    content: content,
                    buttons: {
                        confirm: {
                            text: '确认',
                            btnClass: 'btn-primary',
                            action: function () {
                                window.location.reload();
                            }
                        }
                    }
                });
            }else{
                $.alert("插入失败");
            }
        }),
        error:(function() {
            $.alert("插入出错！");
        })
    });
}

/**
 * 去除重复的数据
 */
function updateRepeatData() {
    $.ajax({
        url: '/contact/updateRepeatData',
        type: 'POST',
        dataType:"json",
        contentType:false,
        data:"",
        success:(function(data) {
            if(data.code == "000000"){
                //插入数量
                var importCallNum = data.data;
                //导入数量大于0
                var content = "成功插入"+importCallNum+"条数据";

                $.alert({
                    title: '提示',
                    content: content,
                    buttons: {
                        confirm: {
                            text: '确认',
                            btnClass: 'btn-primary',
                            action: function () {
                                window.location.reload();
                            }
                        }
                    }
                });
            }else{
                $.alert("插入失败");
            }
        }),
        error:(function() {
            $.alert("插入出错！");
        })
    });
}


//导入客户原始数据
function importCustomerRawDataList() {
    if (!document.getElementById('importCustomerRawDataFile').files[0]) {
        $.alert({
            title: '温馨提示',
            content: '请选择文件！',
        });
        return;
    }
    var fileName = document.getElementById('importCustomerRawDataFile').files[0].name;
    var fileType = fileName.substring(fileName.lastIndexOf("."), fileName.length);
    var formData = new FormData();
    //接口接收参数 键值形式 添加到formData中
    formData.append("file",$("#importCustomerRawDataFile")[0].files[0]);
    if (fileName!="" && (fileType.toLocaleUpperCase()==".XLSX" || fileType.toLocaleUpperCase()==".XLS")) {
        $.ajax({
            url: '/customerImport/customerRawDataImport',
            type: 'POST',
            dataType:"json",
            contentType:false,
            data: formData,
            processData: false,
            success:(function(data) {
                if(data.code == "000000"){
                    //客户导入数量
                    var importNum = data.data.importNum;
                    var importFailIdStr = data.data.importFailIdStr;

                    //返回内容
                    var content = "";

                    //导入数量大于0
                    if(importNum>0){
                        content = "成功导入"+importNum+"条数据";
                    } else {
                        content = "成功导入0条数据";
                    }
                    //失败id不为空
                    if(importFailIdStr!=""){
                        content = content + "<br>客户为第：" + importFailIdStr + "行数据，导入失败";
                    }
                    $.alert({
                        title: '提示',
                        content: content,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'btn-primary',
                                action: function () {
                                    $("#importCustomerRawDataFile").val("");
                                }
                            }
                        }
                    });
                    $("#importCustomerRawDataFile").val("");
                } else {
                    $.alert("导入失败");
                    $("#importCustomerRawDataFile").val("");
                }
            }),
            error:(function() {
                $.alert("导入出错！");
                $("#importCustomerRawDataFile").val("");
            })
        });
    } else {
        $.alert({
            title: '温馨提示',
            content: '请上传.xlsx文件！',
        });
    }
}

function importReturnMoneyReplenish(){
    if(!document.getElementById('returnMoneyFile').files[0]){
        $.alert({
            title: '温馨提示',
            content: '请选择文件！',
        });
        return;
    }
    var fileName = document.getElementById('returnMoneyFile').files[0].name;
    var fileType = fileName.substring(fileName.lastIndexOf("."), fileName.length);
    var formData = new FormData();
    //接口接收参数 键值形式 添加到formData中
    formData.append("file",$("#returnMoneyFile")[0].files[0]);
    formData.append("companyId",$("#returnMoneyCompanySelect").val());
    if(fileName!="" && fileType.toLocaleUpperCase()==".XLSX"){
        $.ajax({
            url: '/returnMoney/addReturnMoneyCustomerInfo',
            type: 'POST',
            dataType:"json",
            contentType:false,
            data: formData,
            processData: false,
            success:(function(data) {
                if(data.code == "000000"){
                    $.alert(data.data);
                }else{
                    $.alert("导入失败");
                }
            }),
            error:(function() {
                $.alert("导入出错！");
            })
        });
    } else {
        $.alert({
            title: '温馨提示',
            content: '请上传.xlsx文件！',
        });
    }
}

